package com.yycx.module.bus.provider.handler.haiying.ackamount;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.hy.BusHyorderReturn;
import com.yycx.module.bus.client.entity.hy.HyOrder;
import org.springframework.stereotype.Component;

/**
 * 未回款订单
 *
 * @author zyf
 */
@Component
public class HyReturnAmountTab1PageListHandler implements PageInterceptor<BusHyorderReturn> {


    @Override
    public void prepare(CriteriaQuery<BusHyorderReturn> cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        OpenUser openUser = OpenHelper.getUser();
        Long companyId = openUser.getCompanyId();
        cq.addSelect(HyOrder.class, "orderId", "orderNo","outOrderNo", "sendDate", "businessCode", "sendState", "sendType", "customBondType", "saleManName");
        cq.addSelect(BusHyorderReturn.class,"orderDetailsReturnId", "orderDetailsId", "saleType", "deptId", "parentId", "returnId", "drugsName", "drugsSpec", "drugType", "salePrice", "saleNum", "saleAmount", "returnDate", "returnAmount", "customFloorAmount", "customBond", "customBondTakeAmount", "customBondDate", "deptPrice", "deptSettleAmount");
        cq.addSelect(BusCustom.class, "customName", "settleType");
        cq.addSelect(BusDept.class, "deptName");
        cq.like(HyOrder.class, "orderNo");
        cq.like(HyOrder.class, "saleManName");
        cq.like(BusCustom.class, "customName");
        cq.eq(BusHyorderReturn.class, "drugType");
        cq.ge(FlymeUtils.isNotEmpty(beginDate), "bhd.sendDate", beginDate);
        cq.le(FlymeUtils.isNotEmpty(endDate), "bhd.sendDate", endDate);
        cq.eq(true, "ho.companyId", companyId);
        cq.eq(HyOrder.class, "deptId");
        //数据筛选条件
        cq.isNull("bhr.returnId");
        //回款状态
        cq.eq("bhr.customReturnState", CommonConstants.INT_0);
        //关联表条件
        cq.createJoin(BusCustom.class);
        cq.createJoin(BusDept.class);
        cq.createJoin(HyOrder.class);
        cq.orderByDesc("ho.createDate");
        cq.orderByAsc("ho.orderNo");
    }

}
